package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.mapper.UserMapper;
import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.Departments;
import com.sweet.fourtimeoa.pojo.entity.Roles;
import com.sweet.fourtimeoa.pojo.vo.DepartmentVo;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.SystemService;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "系统管理")
@RestController
@RequestMapping("/oa/system")
@CrossOrigin(origins = "*")
public class SystemController {
    @Autowired
    private SystemService systemService;

    @Operation(summary = "角色管理_分页查询")
    @GetMapping("/queryRolesList")
    public Result queryRolesList(PageDto pageDto) {
        PageVo<Roles> documentList = systemService.queryRolesList(pageDto.getPageNum(), pageDto.getPageSize());
        return Result.success(documentList);
    }
    @Operation(summary = "角色管理_删除")
    @DeleteMapping("/deleteRoles/{roleId}")
    public Result deleteRoles(@PathVariable Integer roleId) {
        systemService.deleteRoles(roleId);
        return Result.success();
    }
    @Operation(summary = "角色管理_新增")
    @PostMapping("/insertRoles")
    public Result insertRoles(String roleName1) {
        systemService.insertRoles(roleName1);
        return Result.success();
    }
    @Operation(summary = "角色管理_修改_获取数据")
    @GetMapping("/getByUpdateRoles/{roleId}")
    public Result getByUpdateRoles(@PathVariable Integer roleId) {
        return Result.success(systemService.getByUpdateRoles(roleId));
    }
    @Operation(summary = "角色管理_修改")
    @PutMapping("/updateRoles")
    public Result updateRoles(@RequestBody Roles roles) {
        systemService.updateRoles(roles);
        return Result.success();
    }


//    @Operation(summary = "用户管理_分页查询")
//    @GetMapping("/querySystemUserList")
//    public Result querySystemUserList(@RequestBody PageDto<SystemUserQueryDto> pageDto) {
//        PageVo<SystemUserQueryDto> documentList = userMapper.querySystemUserList(pageDto);
//        return Result.success(documentList);
//    }
    //部门结构管理
    @Operation(summary = "获取全部部门")
    @GetMapping("/getAllDepartment")
    public Result getAllDepartment(){
         List<DepartmentVo> departmentVos = systemService.getAllDepartment();
        return Result.success(departmentVos);
    }

    //根据id获取部门信息
    @Operation(summary = "根据id获取部门信息")
    @GetMapping("/getDepartmentById/{id}")
    public Result getDepartmentsById(@PathVariable Integer id){
        Departments departments = systemService.getDepartmentsById(id);
        return Result.success(departments);
    }

    //根据父节点id获取部门信息
    @Operation(summary = "根据父节点id获取部门信息")
    @GetMapping("/getDepartmentByParentId/{parentId}")
    public Result getDepartmentsByParentId(@PathVariable Integer parentId){
        Departments departments = systemService.getDepartmentsById(parentId);
        return Result.success(departments);
    }


    //修改部门信息
    @Operation(summary = "修改部门信息")
    @PutMapping("/updateDepartment")
    public Result updateDepartments(@RequestBody Departments departments){
        systemService.updateDepartments(departments);
        return Result.success();
    }

    @Operation(summary = "新增部门")
    @PostMapping("/insertDepartment")
    public Result insertDepartment(@RequestBody Departments departments){
        systemService.insertDepartment(departments);
        return Result.success();
    }

    //删除部门
    @Operation(summary = "删除部门")
    @DeleteMapping("/deleteDepartment/{id}")
    public Result deleteDepartment(@PathVariable Integer id){
        systemService.deleteDepartment(id);
        return Result.success();
    }
}
